Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Nov 4, 2025

Fixes concurrent resumption flows that can cause two instances behavior when UI cancel schedules presentResumableAsk via setImmediate and webview checkpoint restore calls cancel then restore. Both flows can reset abort flags and call into task loop simultaneously.

Solution: Add suppressResumeAsk flag in ClineProvider to gate scheduling during transactions, plus resumeAskScheduledForTaskId dedupe to prevent multiple asks per task. Wrap checkpoint restore flow with suppression to serialize with cancel path.

Testing: Extended existing tests and added new test for checkpoint restore suppression. All 10 tests across 4 files pass.
Related to: #8986
Addresses PR 8986 recommendations for provider-level resumption serialization.


Important

Introduces suppression and deduplication in ClineProvider to prevent concurrent task resumptions, with tests added for validation.

  • Behavior:
    • Adds suppressResumeAsk flag and resumeAskScheduledForTaskId in ClineProvider to prevent concurrent resumptions.
    • Wraps checkpoint restore flow in webviewMessageHandler.ts with suppression to serialize with cancel path.
  • Functions:
    • Modifies cancelTask() in ClineProvider to check suppressResumeAsk and deduplicate presentResumableAsk scheduling.
    • Updates webviewMessageHandler() to set suppressResumeAsk during checkpoint restore.
  • Testing:
    • Adds tests in ClineProvider.cancelTask.present-ask.spec.ts for suppression and deduplication logic.
    • Adds webviewMessageHandler.resume-gating.spec.ts to test suppression during checkpoint restore.

This description was created by Ellipsis for 7827cb7. You can customize this summary. It will automatically update as commits are pushed.

Fixes concurrent resumption flows that can cause 'two instances' behavior when:
- UI cancel schedules presentResumableAsk via setImmediate
- Webview checkpoint restore calls cancel then restore
- Both flows reset abort flags and call into task loop simultaneously

Changes:
- Add suppressResumeAsk flag in ClineProvider to gate scheduling during transactions
- Add resumeAskScheduledForTaskId dedupe to prevent multiple scheduled asks per task
- Wrap checkpoint restore flow with suppression to serialize with cancel path
- Enhanced scheduling guards: re-check suppression, verify task not switched/abandoned
- Unit tests for gating behavior and deduplication

Addresses PR #8986 recommendations for provider-level resumption serialization.
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners November 4, 2025 16:31
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Nov 4, 2025
@roomote
Copy link

roomote bot commented Nov 4, 2025

See this task on Roo Code Cloud

Reviewed the race condition fix. Found 1 issue that needs to be addressed:

Mention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request.

Comment on lines 1054 to 1058
} finally {
// End transaction and post consolidated state
await provider.endStateTransaction()
provider.setSuppressResumeAsk(false)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If endStateTransaction() throws an exception, setSuppressResumeAsk(false) on line 1057 won't execute, leaving the suppression flag permanently set to true. This would prevent all future resume asks from being scheduled until VS Code is restarted. Nest the cleanup in a second try-finally block to guarantee the flag is always reset:

} finally {
    try {
        await provider.endStateTransaction()
    } finally {
        provider.setSuppressResumeAsk(false)
    }
}

Fix it with Roo Code or mention @roomote and request a fix.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 4, 2025
@daniel-lxs daniel-lxs closed this Nov 4, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Nov 4, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 4, 2025
@daniel-lxs daniel-lxs deleted the hotfix/cancel-resume-race-condition branch November 4, 2025 16:54
@daniel-lxs daniel-lxs restored the hotfix/cancel-resume-race-condition branch November 4, 2025 18:57
@daniel-lxs daniel-lxs reopened this Nov 4, 2025
@github-project-automation github-project-automation bot moved this from Done to Triage in Roo Code Roadmap Nov 4, 2025
@github-project-automation github-project-automation bot moved this from Done to New in Roo Code Roadmap Nov 4, 2025
@roomote
Copy link

roomote bot commented Nov 4, 2025

See this task on Roo Code Cloud

Reviewing your PR now. Feedback coming soon!

Mention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request.

@daniel-lxs daniel-lxs closed this Nov 4, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 4, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Nov 4, 2025
@daniel-lxs daniel-lxs deleted the hotfix/cancel-resume-race-condition branch November 4, 2025 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants